import datetime
from django.forms.widgets import HiddenInput
from opengoal.models import Goal, Journal, Task
from tinymce.widgets import TinyMCE
from opengoal.widgets import RichTimeInput

__author__ = 'Sharp'

from django import forms

class GoalForm(forms.ModelForm):

    name = forms.CharField(
        widget=forms.TextInput(attrs={'class': 'span10'}),
        label='Goal Name: What is your goal?',
        help_text='e.g. Become financially free in 5 years',
        initial='')

    description = forms.CharField(
        label='Description',
        widget=TinyMCE(attrs={'cols': 80, 'rows': 20}))

    start_date = forms.DateField(
        widget=forms.DateInput(attrs={'class': 'datepicker'}),
        initial=datetime.date.today().isoformat(),
        label='Start Date: When do you plan to start on it?')

    due_date = forms.DateField(
        widget=forms.DateInput(attrs={'class': 'datepicker'}),
        label='Deadline: When will it be achieved?', initial='')

    categories = forms.CharField(
        required=False,
        widget=forms.TextInput(attrs={'class': 'span10 has_helper_select'}),
        label='Categories: What categories does it belongs to?',
        initial='')

    show_on_dashboard = forms.BooleanField(
        required=False,
        label='Show this goal on Dashboard',
        initial=True)

    goal = forms.IntegerField(
        required=False,
        widget=HiddenInput()
    )

    class Meta:
        model = Goal
        fields = ('name', 'description', 'start_date', 'due_date', 'show_on_dashboard', 'categories')

class SubGoalForm(forms.ModelForm):

    name = forms.CharField(
        widget=forms.TextInput(attrs={'class': 'span10'}),
        label='Subgoal name: What is your goal?',
        help_text='e.g. Become financially free in 5 years',
        initial='')

    description = forms.CharField(
        label='Description',
        widget=TinyMCE(attrs={'cols': 80, 'rows': 20}))

    due_date = forms.DateField(
        widget=forms.DateInput(attrs={'class': 'datepicker'}),
        label='Deadline: When will it be achieved?', initial='')

    show_on_dashboard = forms.BooleanField(
        required=False,
        label='Show this goal on Dashboard',
        initial=True)

    parent = forms.IntegerField(
        widget=HiddenInput()
    )

    goal = forms.IntegerField(
        required=False,
        widget=HiddenInput()
    )


    class Meta:
        model = Goal
        fields = ('name', 'description', 'due_date', 'show_on_dashboard')


class JournalForm(forms.ModelForm):
    tags = forms.CharField(max_length=200, required=False)

    title = forms.CharField(
        widget=forms.TextInput(attrs={'class': 'span10'}),
        max_length=200,
        label='Title:',
        required=False,
        help_text='Optional')

    content = forms.CharField(
        widget=TinyMCE(attrs={'cols': 80, 'rows': 20}),
        label='Content:',
        help_text='To protect your privacy, data entered here will be saved on server in encrypted format and only decrypted when displayed back to you.'\
                  'Your journal entries are completely confidental.'
    )
    tags = forms.CharField(
        max_length=200,
        required=False,
        widget=forms.TextInput(attrs={'class': 'span10'}),)

    class Meta:
        model = Journal
        fields = ('goal', 'title', 'content')

class TaskForm(forms.ModelForm):
    name = forms.CharField(
        widget=forms.TextInput(attrs={'class': 'span10'}),
        label='Enter task or action step',
        help_text='e.g. Brainstorm for business ideas',
        initial=''
    )

    note = forms.CharField(
        widget=TinyMCE(attrs={'cols': 80, 'rows': 20}),
        label='Note:',
        required=False
    )

    due_date = forms.DateField(
        widget=forms.DateInput(attrs={'class': 'datepicker'}),
        label='When is the due date?', initial='')

    estimated_time = forms.TimeField(
        required=False,
        widget=RichTimeInput(attrs={'class': 'span2'}),
        label='Estimated completion time',
        help_text='format: "h:mm"'
    )


    goal = forms.IntegerField(
        required=False,
        widget=HiddenInput()
    )

    task = forms.IntegerField(
        required=False,
        widget=HiddenInput()
    )

    tags = forms.CharField(
        max_length=200,
        required=False,
        widget=forms.TextInput(attrs={'class': 'span10'}),)

    class Meta:
        model = Task
        fields = ('name', 'note', 'due_date', 'tags', 'estimated_time')